package com.yans.managers.vo
{
	import com.yans.interfaces.ILoaderResult;
	import com.yans.managers.consts.LoaderType;
	
	public class LoaderResult implements ILoaderResult
	{ 
		private var _type:int, _url:String, _data:Object;
		private var _target:Object;
		/**
		 *	@inheritDoc
		 */		
		public function LoaderResult(type:int, url:String, target:Object) {
			_type = type;
			_url = url;
			_target = target;
		}
		
		/**
		 *	@inheritDoc
		 */		
		public function get type():int
		{
			return _type;
		}
		
		/**
		 *	@inheritDoc
		 */		
		public function get name():String
		{
			if(_url) {
				var arr:Array;
				if(_url.indexOf("/") > -1) {
					arr = _url.split("/");	
				}
				else arr = _url.split("\\");
				return arr[arr.length - 1].toString();
			}
			return null;
		}
		
		/**
		 *	@inheritDoc
		 */	
		public function get target():Object
		{ 
			return _target;
		}
		
		/**
		 *	@inheritDoc
		 */	
		public function get data():Object
		{
			if(!_data) {
				if(_type == LoaderType.LOADER) {
					_data = _target.content;
				}
				else if(_type == LoaderType.URLLOADER) {
					_data = _target.data;
				}
				else {
					_data = _target;
				}
			}
			return _data;
		}
		
		/**
		 *	@inheritDoc
		 */	
		public function get url():String
		{
			return _url;
		}
		
		/**
		 *	@inheritDoc
		 */	
		public function dispose():void { 
			_url = null;
			_data = null;
		}
		
		/**
		 *	@inheritDoc
		 */	
		public function init(data:Object = null):void { 
		}
		
	}
}